﻿/*=================================================================================================
// <copyright company="AltaModa Technologies, LLC">
//	Copyright (c) AltaModa Technologies, LLC. All rights reserved.
//	http://www.AltaModaTech.com/
// </copyright>
// 
//	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
//	IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
//	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
//	CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
//	CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
//	SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
//	THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
//	OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
//	POSSIBILITY OF SUCH DAMAGE.
//===============================================================================================*/

using System;

namespace AMT.Web.Security
{
	/// <summary>
	/// Provides restricted role membership (authorization).  This class is for development and debug purposes; DO NOT USE IN PRODUCTION!
	/// Role membership queries, role administration, etc. always fail; these behaviors can not be changed via properties.  The primary 
	/// purpose of this class is to serve as the base for classes that just need to implement a few parts of RoleProvider's interface.
	/// </summary>
	public class DenyAllRoleProvider : System.Web.Security.RoleProvider
	{
		public override string Description
		{
			get
			{
				return "AMT.Web.Security.Debug.DenyAllRoleProvider - DO NOT use in production systems";
			}
		}

		// TODO: consider: should this method always throw?  If it does not indicate that users were not added to the roles,
		// derived classes will be tricked into believing this method worked correctly
		/// <summary>
		/// Users are never added to any roles; do-nothing method
		/// </summary>
		/// <param name="usernames">[ignored]</param>
		/// <param name="roleNames">[ignored]</param>
		public override void AddUsersToRoles(string[] usernames, string[] roleNames)
		{
			return;
		}

		// REVIEW: any useful reason for this property to fail or throw?
		/// <summary>
		/// Retains any string set as the application name
		/// </summary>
		public override string ApplicationName { get; set; }

		/// <summary>
		/// Roles are never created; do-nothing method
		/// </summary>
		/// <param name="roleName">[ignored]</param>
		public override void CreateRole(string roleName)
		{
			return;
		}

		/// <summary>
		/// Never deletes role; always returns false
		/// </summary>
		/// <param name="roleName">[ignored]</param>
		/// <param name="throwOnPopulatedRole">Flag indicating whether method should throw exception </param>
		/// <returns>false when throwOnPopulatedRole is false</returns>
		/// <exception cref="System.Exception">Always thrown when throwOnPopulatedRole is true</exception>
		public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
		{
			if (throwOnPopulatedRole) throw new Exception("Simulated: Role is not empty.");

			return false;
		}

		/// <summary>
		/// Always fails by returning null array
		/// </summary>
		/// <param name="roleName"></param>
		/// <param name="usernameToMatch"></param>
		/// <returns>null string array</returns>
		public override string[] FindUsersInRole(string roleName, string usernameToMatch)
		{
			return null;
		}

		/// <summary>
		/// Always fails by returning null array
		/// </summary>
		/// <param name="roleName"></param>
		/// <param name="usernameToMatch"></param>
		/// <returns>null string array</returns>
		public override string[] GetAllRoles()
		{
			return null;
		}

		/// <summary>
		/// Always fails by returning null array
		/// </summary>
		/// <param name="roleName"></param>
		/// <param name="usernameToMatch"></param>
		/// <returns>null string array</returns>
		public override string[] GetRolesForUser(string username)
		{
			return null;
		}

		/// <summary>
		/// Always fails by returning null array
		/// </summary>
		/// <param name="roleName"></param>
		/// <param name="usernameToMatch"></param>
		/// <returns>null string array</returns>
		public override string[] GetUsersInRole(string roleName)
		{
			return null;
		}

		/// <summary>
		/// User is never in the role; always return false
		/// </summary>
		/// <param name="username"></param>
		/// <param name="roleName"></param>
		/// <returns>false</returns>
		public override bool IsUserInRole(string username, string roleName)
		{
			return false;
		}

		public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
		{
			return;
		}

		/// <summary>
		/// Role never exists; always returns false
		/// </summary>
		/// <param name="roleName"></param>
		/// <returns>false</returns>
		public override bool RoleExists(string roleName)
		{
			return false;
		}
	}
}
